
import numpy
from speck import Speck

def save(filename, s, mode = 'w'):
    f = open(filename, mode)
    f.write("%d\n" % len(s))
    f.write("made in specks\n")
    for i in range(len(s)):
        f.write("%4s %12.12f %12.12f %12.12f\n" % (s.symbols[i], s.r[i][0], s.r[i][1], s.r[i][2]))
        
def load(filename):
    f = open(filename, 'r')
    lines = f.readlines()
    index = 0
    f.close()
    path = []
    while index < len(lines):
        s = Speck()
        n = int(lines[index].strip())
        index += 1
        comment = lines[index].strip()
        index += 1
        for i in range(n):
            split = lines[index].strip().split()
            index += 1
            s.addAtom(split[0], [float(split[1]), float(split[2]), float(split[3])])
        path.append(s)
    return path
    
    
